home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / ext / events / gajim_status.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  7KB  |  189 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import sys
  6. if os.name == 'nt' or sys.platform == 'darwin':
  7.     from quodlibet.plugins import PluginNotSupportedError
  8.     raise PluginNotSupportedError
  9. from string import join
  10. from gi.repository import Gtk
  11. import dbus
  12. from quodlibet.plugins.events import EventPlugin
  13. from quodlibet.parse import Pattern
  14. from quodlibet.qltk import Frame
  15. from quodlibet import config
  16.  
  17. class GajimStatusMessage(EventPlugin):
  18.     PLUGIN_ID = 'Gajim status message'
  19.     PLUGIN_NAME = _('Gajim Status Message')
  20.     PLUGIN_DESC = _('Change Gajim status message according to what you are currently listening to.')
  21.     PLUGIN_VERSION = '0.7.4'
  22.     c_accounts = __name__ + '_accounts'
  23.     c_paused = __name__ + '_paused'
  24.     c_statuses = __name__ + '_statuses'
  25.     c_pattern = __name__ + '_pattern'
  26.     
  27.     def __init__(self):
  28.         
  29.         try:
  30.             self.accounts = config.get('plugins', self.c_accounts).split()
  31.         except:
  32.             self.accounts = []
  33.             config.set('plugins', self.c_accounts, '')
  34.  
  35.         
  36.         try:
  37.             self.paused = config.getboolean('plugins', self.c_paused)
  38.         except:
  39.             self.paused = True
  40.             config.set('plugins', self.c_paused, 'True')
  41.  
  42.         
  43.         try:
  44.             self.statuses = config.get('plugins', self.c_statuses).split()
  45.         except:
  46.             self.statuses = [
  47.                 'online',
  48.                 'chat']
  49.             config.set('plugins', self.c_statuses, join(self.statuses))
  50.  
  51.         
  52.         try:
  53.             self.pattern = config.get('plugins', self.c_pattern)
  54.         except:
  55.             self.pattern = '<artist> - <title>'
  56.             config.set('plugins', self.c_pattern, self.pattern)
  57.  
  58.  
  59.     
  60.     def enabled(self):
  61.         self.interface = None
  62.         self.current = ''
  63.  
  64.     
  65.     def disabled(self):
  66.         if self.current != '':
  67.             self.change_status(self.accounts, '')
  68.  
  69.     
  70.     def change_status(self, enabled_accounts, status_message):
  71.         if not self.interface:
  72.             
  73.             try:
  74.                 bus = dbus.SessionBus()
  75.                 obj = bus.get_object('org.gajim.dbus', '/org/gajim/dbus/RemoteObject')
  76.                 self.interface = dbus.Interface(obj, 'org.gajim.dbus.RemoteInterface')
  77.             except dbus.DBusException:
  78.                 self.interface = None
  79.             
  80.  
  81.         if self.interface:
  82.             
  83.             try:
  84.                 for account in self.interface.list_accounts():
  85.                     status = self.interface.get_status(account)
  86.                     if enabled_accounts != [] and account not in enabled_accounts:
  87.                         continue
  88.                     if status in self.statuses:
  89.                         self.interface.change_status(status, status_message, account)
  90.                         continue
  91.             except dbus.DBusException:
  92.                 self.interface = None
  93.             
  94.  
  95.  
  96.     
  97.     def plugin_on_song_started(self, song):
  98.         if song:
  99.             self.current = Pattern(self.pattern) % song
  100.         else:
  101.             self.current = ''
  102.         self.change_status(self.accounts, self.current)
  103.  
  104.     
  105.     def plugin_on_paused(self):
  106.         if self.paused and self.current != '':
  107.             self.change_status(self.accounts, self.current + ' [paused]')
  108.  
  109.     
  110.     def plugin_on_unpaused(self):
  111.         self.change_status(self.accounts, self.current)
  112.  
  113.     
  114.     def accounts_changed(self, entry):
  115.         self.accounts = entry.get_text().split()
  116.         config.set('plugins', self.c_accounts, entry.get_text())
  117.  
  118.     
  119.     def pattern_changed(self, entry):
  120.         self.pattern = entry.get_text()
  121.         config.set('plugins', self.c_pattern, self.pattern)
  122.  
  123.     
  124.     def paused_changed(self, c):
  125.         config.set('plugins', self.c_paused, str(c.get_active()))
  126.  
  127.     
  128.     def statuses_changed(self, b):
  129.         if b.get_active() and b.get_name() not in self.statuses:
  130.             self.statuses.append(b.get_name())
  131.         elif b.get_active() is False and b.get_name() in self.statuses:
  132.             self.statuses.remove(b.get_name())
  133.         config.set('plugins', self.c_statuses, join(self.statuses))
  134.  
  135.     
  136.     def PluginPreferences(self, parent):
  137.         vb = Gtk.VBox(spacing = 3)
  138.         pattern_box = Gtk.HBox(spacing = 3)
  139.         pattern_box.set_border_width(3)
  140.         pattern = Gtk.Entry()
  141.         pattern.set_text(self.pattern)
  142.         pattern.connect('changed', self.pattern_changed)
  143.         pattern_box.pack_start(Gtk.Label(label = 'Pattern:'), True, True, 0)
  144.         pattern_box.pack_start(pattern, True, True, 0)
  145.         accounts_box = Gtk.HBox(spacing = 3)
  146.         accounts_box.set_border_width(3)
  147.         accounts = Gtk.Entry()
  148.         accounts.set_text(join(self.accounts))
  149.         accounts.connect('changed', self.accounts_changed)
  150.         accounts.set_tooltip_text(_('List accounts, separated by spaces, for changing status message. If none are specified, status message of all accounts will be changed.'))
  151.         accounts_box.pack_start(Gtk.Label(label = 'Accounts:'), True, True, 0)
  152.         accounts_box.pack_start(accounts, True, True, 0)
  153.         c = Gtk.CheckButton(label = "Add '[paused]'")
  154.         c.set_active(self.paused)
  155.         c.connect('toggled', self.paused_changed)
  156.         c.set_tooltip_text(_("If checked, '[paused]' will be added to status message on pause."))
  157.         table = Gtk.Table()
  158.         self.list = []
  159.         i = 0
  160.         j = 0
  161.         for status in [
  162.             'online',
  163.             'offline',
  164.             'chat',
  165.             'away',
  166.             'xa',
  167.             'invisible']:
  168.             button = Gtk.CheckButton(label = status)
  169.             button.set_name(status)
  170.             if status in self.statuses:
  171.                 button.set_active(True)
  172.             button.connect('toggled', self.statuses_changed)
  173.             self.list.append(button)
  174.             table.attach(button, i, i + 1, j, j + 1)
  175.             if i == 2:
  176.                 i = 0
  177.                 j += 1
  178.                 continue
  179.             i += 1
  180.         
  181.         vb.pack_start(pattern_box, True, True, 0)
  182.         vb.pack_start(accounts_box, True, True, 0)
  183.         vb.pack_start(c, True, True, 0)
  184.         vb.pack_start(Frame(label = _('Statuses for which status message\nwill be changed')), True, True, 0)
  185.         vb.pack_start(table, True, True, 0)
  186.         return vb
  187.  
  188.  
  189.